﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;

namespace PSE.ProcessManager.Entity
{
    [Serializable]
    public class InstanceEntity
    {
        public InstanceEntity()
        {
            this.ProcessId = -1;
            this.ProcessIds = new List<int>();
        }

        [System.Xml.Serialization.XmlIgnore()]
        public int ProcessId
        {
            get;
            set;
        }

        [System.Xml.Serialization.XmlAttribute()]
        public string Name
        {
            get;
            set;
        }

        public string Address
        {
            get;
            set;
        }

        [System.Xml.Serialization.XmlIgnore()]
        public Uri UriAddress
        {
            get
            {
                return new Uri(Address);
            }
        }

        [System.Xml.Serialization.XmlArrayItem(ElementName = "ProcessId")]
        public List<int> ProcessIds
        {
            get;
            set;
        }

        //static string _filePath;
        //static InstanceEntity()
        //{
        //    _filePath = Path.GetDirectoryName(System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath) + @"\InstancesConfig.xml";
        //}

        //public static List<InstanceEntity> LodFromFile()
        //{
        //    if (!File.Exists(_filePath))
        //        return null;
        //    else
        //    {
        //        PSE.Framework.Serialization.XmlSerializer ser = new PSE.Framework.Serialization.XmlSerializer(typeof(List<InstanceEntity>));
        //        return ser.DeserializeFromFile<List<InstanceEntity>>(_filePath);
        //    }
        //}

        //public static void SaveToFile(List<InstanceEntity> collection)
        //{
        //    PSE.Framework.Serialization.XmlSerializer ser = new PSE.Framework.Serialization.XmlSerializer(typeof(List<InstanceEntity>));
        //    ser.SerializeToFile(_filePath, collection);
        //}
    }
}
